package com.freewater.springboot.demo.ioc.eventlistener;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);
        applicationContext.registerShutdownHook();
        applicationContext.start();
        applicationContext.start();
        applicationContext.publishEvent(new CustomEvent(CustomEvent.LEVEL_INFO, "info"));
        applicationContext.publishEvent(new CustomEvent(CustomEvent.LEVEL_WARN, "warn"));
        applicationContext.publishEvent(new CustomEvent(CustomEvent.LEVEL_ERROR, "error"));
        applicationContext.publishEvent(new EntityCreatedEvent<>(new Person("zhangsan")));
        applicationContext.publishEvent(new EntityCreatedEvent<>(new Animal("my dog")));
        TimeUnit.SECONDS.sleep(3);
        applicationContext.close();
    }
}
